- has_impersonation_link = header_link?(:admin_impersonation)
- user_status_data = user_status_properties(current_user)

%header.navbar.navbar-gitlab.navbar-expand-sm.js-navbar{ data: { qa_selector: 'navbar' } }
  %a.gl-sr-only.gl-accessibility{ href: "#content-body" } Skip to content
  .container-fluid
    .header-content.js-header-content
      .title-container.hide-when-top-nav-responsive-open.gl-transition-medium.gl-display-flex.gl-align-items-stretch.gl-pt-0.gl-mr-3
        .title
          %span.gl-sr-only GitLab
          = link_to root_path, title: _('Homepage'), id: 'logo', class: 'has-tooltip', **tracking_attrs('main_navigation', 'click_gitlab_logo_link', 'navigation_top') do
            = brand_header_logo
        .gl-display-flex.gl-align-items-center
          - if Gitlab.com_and_canary?
            = gl_badge_tag({ variant: :success, size: :sm }, { href: Gitlab::Saas.canary_toggle_com_url, data: { qa_selector: 'canary_badge_link' }, target: :_blank, rel: 'noopener noreferrer', class: 'canary-badge' }) do
              = _('Next')

        - if current_user
          .gl-display-none.gl-sm-display-block
            = render "layouts/nav/top_nav"
        - else
          - if Gitlab.com?
            = render 'layouts/header/marketing_links'
          - else
            .gl-display-none.gl-sm-display-block
              = render "layouts/nav/top_nav"

      - if top_nav_show_search
        .navbar-collapse.gl-transition-medium.collapse.gl-mr-auto.global-search-container.hide-when-top-nav-responsive-open
          - search_menu_item = top_nav_search_menu_item_attrs
          %ul.nav.navbar-nav.gl-w-full.gl-align-items-center
            %li.nav-item.header-search-new.gl-display-none.gl-lg-display-block.gl-w-full
              - unless current_controller?(:search)
                = render 'layouts/header_search'
            %li.nav-item{ class: 'd-none d-sm-inline-block d-lg-none' }
              = link_to search_menu_item.fetch(:href), title: search_menu_item.fetch(:title), aria: { label: search_menu_item.fetch(:title) },
                data: { toggle: 'tooltip', placement: 'bottom', container: 'body',
                track_action: 'click_link',
                track_label: 'global_search',
                track_property: 'navigation_top' } do
                = sprite_icon(search_menu_item.fetch(:icon))

      .navbar-collapse.gl-transition-medium.collapse
        %ul.nav.navbar-nav.gl-w-full.gl-align-items-center.gl-justify-content-end
          - if current_user
            = render 'layouts/header/new_dropdown', class: 'gl-display-none gl-sm-display-block gl-white-space-nowrap gl-text-right'
          - if header_link?(:issues)
            = nav_link(path: 'dashboard#issues', html_options: { class: "user-counter" }) do
              = link_to assigned_issues_dashboard_path, title: _('Issues'), class: 'dashboard-shortcuts-issues js-prefetch-document', aria: { label: _('Issues') },
                data: { qa_selector: 'issues_shortcut_button', toggle: 'tooltip', placement: 'bottom',
                track_label: 'main_navigation',
                track_action: 'click_issues_link',
                track_property: 'navigation_top',
                container: 'body' } do
                = sprite_icon('issues')
                - issues_count = assigned_issuables_count(:issues)
                = gl_badge_tag({ size: :sm, variant: :success }, { class: "gl-ml-n2 #{'gl-display-none' if issues_count == 0}", "aria-label": n_("%d assigned issue", "%d assigned issues", issues_count) % issues_count }) do
                  = assigned_open_issues_count_text
          - if header_link?(:merge_requests)
            = nav_link(path: 'dashboard#merge_requests', html_options: { class: "user-counter dropdown" }) do
              - top_level_link = assigned_mrs_dashboard_path
              = link_to top_level_link, class: 'dashboard-shortcuts-merge_requests has-tooltip', title: _('Merge requests'), aria: { label: _('Merge requests') },
                data: { qa_selector: 'merge_requests_shortcut_button',
                toggle: "dropdown",
                placement: 'bottom',
                track_label: 'merge_requests_menu',
                track_action: 'click_dropdown',
                track_property: 'navigation_top',
                container: 'body' } do
                = sprite_icon('git-merge')
                = gl_badge_tag({ size: :sm, variant: :warning }, { class: "js-merge-requests-count gl-ml-n2 #{'gl-display-none' if user_merge_requests_counts[:total] == 0}", "aria-label": n_("%d merge request", "%d merge requests", user_merge_requests_counts[:total]) % user_merge_requests_counts[:total] }) do
                  = number_with_delimiter(user_merge_requests_counts[:total])
                = sprite_icon('chevron-down', css_class: 'caret-down gl-mx-0!')
              .dropdown-menu.dropdown-menu-right
                %ul
                  %li.dropdown-header
                    = _('Merge requests')
                  %li
                    = link_to assigned_mrs_dashboard_path,
                      class: 'gl-display-flex! gl-align-items-center js-prefetch-document',
                      data: {track_action: 'click_link', track_label: 'merge_requests_assigned', track_property: 'navigation_top'} do
                      = _('Assigned')
                      = gl_badge_tag({ variant: :neutral, size: :sm }, { class: "js-assigned-mr-count gl-ml-auto" }) do
                        = user_merge_requests_counts[:assigned]
                  %li
                    = link_to reviewer_mrs_dashboard_path,
                      class: 'dashboard-shortcuts-review_requests gl-display-flex! gl-align-items-center js-prefetch-document',
                      data: {track_action: 'click_link', track_label: 'merge_requests_to_review', track_property: 'navigation_top'} do
                      = _('Review requests')
                      = gl_badge_tag({ variant: :neutral, size: :sm }, { class: "js-reviewer-mr-count gl-ml-auto" }) do
                        = user_merge_requests_counts[:review_requested]
          - if header_link?(:todos)
            = nav_link(controller: 'dashboard/todos', html_options: { class: "user-counter" }) do
              = link_to dashboard_todos_path, title: _('To-Do List'), aria: { label: _('To-Do List') }, class: 'shortcuts-todos js-prefetch-document',
                data: { qa_selector: 'todos_shortcut_button', toggle: 'tooltip', placement: 'bottom',
                track_label: 'main_navigation',
                track_action: 'click_to_do_link',
                track_property: 'navigation_top',
                container: 'body' } do
                = sprite_icon('todo-done')
                -# The todos' counter badge's visibility is being toggled by adding or removing the .hidden class in Js.
                -# We'll eventually migrate to .gl-display-none: https://gitlab.com/gitlab-org/gitlab/-/issues/351792.
                = gl_badge_tag({ size: :sm, variant: :info }, { class: "js-todos-count gl-ml-n2 #{'hidden' if todos_pending_count == 0}", "aria-label": _("Todos count") }) do
                  = todos_count_format(todos_pending_count)
          %li.nav-item.header-help.dropdown.d-none.d-md-block
            = link_to help_path, class: 'header-help-dropdown-toggle gl-relative', data: { toggle: "dropdown", track_action: 'click_question_mark_link', track_label: 'main_navigation', track_property: 'navigation_top' } do
              %span.gl-sr-only
                = s_('Nav|Help')
              = sprite_icon('question-o')
              %span.notification-dot.rounded-circle.gl-absolute
              = sprite_icon('chevron-down', css_class: 'caret-down')
            .dropdown-menu.dropdown-menu-right
              = render 'layouts/header/help_dropdown'
          - if !current_user && Gitlab.com?
            %li.nav-item.gl-display-none.gl-sm-display-block
              = render "layouts/nav/top_nav"
          - if header_link?(:user_dropdown)
            %li.nav-item.header-user.js-nav-user-dropdown.dropdown{ data: { qa_selector: 'user_menu', testid: 'user-menu' }, class: ('mr-0' if has_impersonation_link) }
              = link_to current_user, class: user_dropdown_class, data: { toggle: "dropdown", track_label: "profile_dropdown", track_action: "click_dropdown", track_property: "navigation_top" } do
                = render Pajamas::AvatarComponent.new(current_user, size: 24, class: 'header-user-avatar', avatar_options: { data: { qa_selector: 'user_avatar_content' } })
                = render_if_exists 'layouts/header/user_notification_dot', project: project, namespace: group
                = sprite_icon('chevron-down', css_class: 'caret-down')
              .dropdown-menu.dropdown-menu-right
                = render 'layouts/header/current_user_dropdown'
          - if has_impersonation_link
            %li.nav-item.impersonation.ml-0
              = render Pajamas::ButtonComponent.new(href: admin_impersonation_path, icon: 'incognito', button_options: { title: _('Stop impersonation'), class: 'impersonation-btn', aria: { label: _('Stop impersonation') }, data: { method: :delete, toggle: 'tooltip', placement: 'bottom', container: 'body', qa_selector: 'stop_impersonation_link' } })
          - if header_link?(:sign_in)
            - if allow_signup?
              %li.nav-item
                = render Pajamas::ButtonComponent.new(href: new_user_registration_path) do
                  = _('Register')
            %li.nav-item{ class: 'gl-flex-grow-0! gl-flex-basis-half!' }
              = link_to _('Sign in'), new_session_path(:user, redirect_to_referer: 'yes')

      %button.navbar-toggler.d-block.d-sm-none{ type: 'button', class: 'gl-border-none!', data: { testid: 'top-nav-responsive-toggle', qa_selector: 'mobile_navbar_button' } }
        %span.sr-only= _('Toggle navigation')
        %span.more-icon.gl-px-3.gl-font-sm.gl-font-weight-bold
          %span.gl-pr-2= _('Menu')
          = sprite_icon('hamburger', size: 16)
        = sprite_icon('close', size: 12, css_class: 'close-icon')

- if display_whats_new?
  #whats-new-app{ data: { version_digest: whats_new_version_digest } }

- if can?(current_user, :update_user_status, current_user)
  .js-set-status-modal-wrapper{ data: user_status_data }
